package com.itlong.cloud.utils.string;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class StringUtil {

    /**
     * 判断逗号分隔的值是否有重复
     *
     * @param data
     * @return boolean
     */
    public static boolean isRepeat(String data) {
        String[] list = data.split(",");
        HashMap<String, String> map = new HashMap<>();
        for (String item : list) {
            map.put(item, item);
        }
        return list.length != map.size();
    }

    public static List<String> string2List(String data) {
        String[] list = data.split(",");
        List<String> result = new ArrayList<>();
        for (String item : list) {
            result.add(item);
        }
        return result;
    }

    public static String saveNum(String data) {
        return data.replaceAll("[^0-9]*", "");
    }

}